<?php

/**
 * AuthController
 * 
 * @author Maodo DIOP <dmaodo@gmail.com>
 * @version 
 */

require_once 'Zend/Controller/Action.php';
require_once 'Zend/Auth.php';
require_once 'Zend/Auth/Adapter/DbTable.php';

class MatricebrController extends Zend_Controller_Action {
	
	
public function indexAction()
    {
    	
    	
        $this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
        //$this->view->title = "Supprimer Espece";
        //$this->view->headTitle($this->view->title);
        $matricebr= new Model_DbTable_Matricebr();
        $res = $matricebr->getInfoMatricebr();
        $resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
        
    }
	

    //Action pour ajouter
public function addAction()
    {
 		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
 
    	//if ($this->getRequest()->isPost()) {
		$i = (int)$this->_getParam('i', 0);
		$j =(int)$this->_getParam('j', 0);
		$bassinderetention_idbassinderetention = stripslashes($this->getRequest()->getPost('bassinderetention_idbassinderetention'));
		$proprietaire_idproprietaire = stripslashes($this->getRequest()->getPost('proprietaire_idproprietaire'));
		$type = stripslashes($this->_getParam('type', 0));
        $matricebr = new Model_DbTable_Matricebr();
        $matricebr->addMatricebr($i, $j, $bassinderetention_idbassinderetention, $proprietaire_idproprietaire, $type);  
			//$this->_helper->redirector('index');
		//}
        
        
    }
    
	
    
public function editAction() {
		$form = new Form_Matricebr() ;
		$form->submit->setLabel('Enregistrer');
		$this->view->form = $form;
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {            	
				$id = (int)$this->_getParam('id');
				$i = (int)$form->getValue('i');
				$j = (int)$form->getValue('j');
				$bassinderetention_idbassinderetention = stripslashes($this->getRequest()->getPost('bassinderetention_idbassinderetention'));
				$proprietaire_idproprietaire = stripslashes($this->getRequest()->getPost('proprietaire_idproprietaire'));
				$type = stripslashes($this->getRequest()->getPost('type'));
				
				$matricebr = new Model_DbTable_Matricebr();
				$matricebr->updateMatricebr($id, $i, $j, $bassinderetention_idbassinderetention,$proprietaire_idproprietaire,$type);
				$res = array(); 
				$res = $matricebr->getMatricebr($id);        
				$this->_redirect('/matricebr/index');
			} else {
				$form->populate($formData);
			}
		} else {
			//Si le formulaire n'est pas encore post�
			//Recuperer la valeur de l'objet � editer
			$id = $this->_request->getParam('id', 0);
			if ($idarbre > 0) {
				$matricebr = new Model_DbTable_Matricebr();
				$form->populate($matricebr->getMatricebr($id));
			}
		} 
	}
    
 public function deleteAction()
    {
        $this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
        

            $id = $this->_getParam('id', 0);
            $matricebr = new Model_DbTable_Matricebr();
            $matricebr->deleteMatricebr($id);
            
         $this->_redirect('/matricebr/index');
       
    }
    
 public function allmatricebrAction()
    {
        $this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
        //$this->view->title = "Supprimer Espece";
        //$this->view->headTitle($this->view->title);
        $matricebr = new Model_DbTable_Matricebr();
        $res = $matricebr->getAllMatricebr();
        $resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
       
    }
    
public function getcoordonneeAction()
    {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();

		/*$imin = $this->getRequest()->getPost('imin', 0);
        $imax = $this->getRequest()->getPost('imax', 0);
        $jmin = $this->getRequest()->getPost('jmin', 0);
        $jmax = $this->getRequest()->getPost('jmax', 0);*/
        
        $imin = $this->_request->getParam('imin', 0);
        $imax = $this->_request->getParam('imax', 0);
        $jmin = $this->_request->getParam('jmin', 0);
        $jmax = $this->_request->getParam('jmax', 0);
        
        $matricebr = new Model_DbTable_Matricebr();
        $res = $matricebr->getCoordonneee($imin,$imax,$jmin,$jmax);


    	
        $resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
    	
    }
    

    
    
}

